/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ejercicio.practica3;

import static java.lang.Math.abs;
import static java.lang.Math.pow;
import static java.lang.Math.sqrt;

/**
 *
 * @author manolo
 */
public class Punto {

    private double x;
    private double y;

    public Punto(double x, double y) {
        this.x = x;
        this.y = y;
    }

    public Punto() {
    }

    /**
     * Get the value of y
     *
     * @return the value of y
     */
    public double getY() {
        return y;
    }

    /**
     * Set the value of y
     *
     * @param y new value of y
     */
    public void setY(double y) {
        this.y = y;
    }

    /**
     * Get the value of x
     *
     * @return the value of x
     */
    public double getX() {
        return x;
    }

    /**
     * Set the value of x
     *
     * @param x new value of x
     */
    public void setX(double x) {
        this.x = x;
    }

    public boolean esOrigen() {
        return x == 0 && y == 0;
    }

    public double distancia(Punto p) {
        if (y == 0 && p.getY() == 0) {
            return abs(x) + abs(p.getX());
        } else if (x == 0 && p.getX() == 0) {
            return abs(y) + abs(p.getY());
        } else {
            return sqrt(pow(x - p.getX(), 2) + pow(y - p.getY(), 2));
        }
    }
}
